/*
Copyright (C) 2008, 2009 Henrik Naess

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using MatrixPlugin.Constants;

namespace MatrixPlugin
{
    public class DistanceInfoComparer : IComparer<DistanceInfo>
    {
        public enum ComparisonType
        {
            Time = 1,
            Speed = 2,
            Elevation = 3,
            Distance = 4,
            Pace
        }

        private ComparisonType m_comparisonType;

        public DistanceInfoComparer(ComparisonType comparisonType)
        {
            m_comparisonType = comparisonType;
        }

        public ComparisonType ComparisonMethod
        {
            get { return m_comparisonType; }
            set { m_comparisonType = value; }
        }

        public int Compare(DistanceInfo x, DistanceInfo y)
        {
            return x.CompareTo(y, m_comparisonType);
        }

        public static DistanceInfoComparer GetSortOrder(General.DataValue calcDataValue)
        {
            DistanceInfoComparer comparer;
            switch (calcDataValue)
            {
                case General.DataValue.speed:
                    comparer = new DistanceInfoComparer(ComparisonType.Speed);
                    break;
                case General.DataValue.elevation:
                    comparer = new DistanceInfoComparer(ComparisonType.Elevation);
                    break;
                case General.DataValue.distance:
                    comparer = new DistanceInfoComparer(ComparisonType.Distance);
                    break;
                case General.DataValue.pace:
                    comparer = new DistanceInfoComparer(ComparisonType.Pace);
                    break;
                default:
                    comparer = new DistanceInfoComparer(ComparisonType.Time);
                    break;
            }
            return comparer;
        }
    }
}